package ops.weixin.cp.bean;

import static ops.weixin.common.api.WxConsts.KefuMsgType.TEXT;

import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;

import com.alibaba.fastjson.JSONObject;

import ops.weixin.common.api.WxConsts.KefuMsgType;
import ops.weixin.cp.bean.messagebuilder.TextBuilder;

/**
 * 发送消息体
 * 
 * @author SuM
 * @date: 2019年12月25日下午4:43:31
 */
public class WxCpMessage implements Serializable {
	private static final long serialVersionUID = -2082278303476631708L;

	private Integer agentId;
	private String toUser;
	private String toParty;
	private String toTag;
	private String msgType;
	private String content;
	private String safe;
	private String url;

	/**
	 * 获得文本消息builder.
	 */
	public static TextBuilder TEXT() {
		return new TextBuilder();
	}

	/**
	 * <pre>
	 * 请使用.
	 * {@link KefuMsgType#TEXT}
	 * {@link KefuMsgType#IMAGE}
	 * {@link KefuMsgType#VOICE}
	 * {@link KefuMsgType#MUSIC}
	 * {@link KefuMsgType#VIDEO}
	 * {@link KefuMsgType#NEWS}
	 * {@link KefuMsgType#MPNEWS}
	 * {@link KefuMsgType#MARKDOWN}
	 * {@link KefuMsgType#TASKCARD}
	 * {@link KefuMsgType#MINIPROGRAM_NOTICE}
	 * </pre>
	 *
	 * @param msgType 消息类型
	 */
	public void setMsgType(String msgType) {
		this.msgType = msgType;
	}

	/**
	 * @return 组装发送Json
	 */
	public String toJson() {
		Map<String, Object> fastJsonMap = new HashMap<String, Object>();
		fastJsonMap.put("agentid", this.getAgentId());
		fastJsonMap.put("touser", this.getToUser());
		fastJsonMap.put("msgtype", this.getMsgType());
		fastJsonMap.put("toparty", this.getToParty());
		fastJsonMap.put("totag", this.getToTag());

		switch (this.getMsgType()) {
		case TEXT: {
			Text text = new Text();
			text.setContent(content);
			fastJsonMap.put("text", text);
			break;
		}
		}
		fastJsonMap.put("safe", this.getSafe());

		return JSONObject.toJSONString(fastJsonMap);
	}

	public class Text {
		private String content; // 文本内容

		public void setContent(String content) {
			this.content = content;
		}

		public String getContent() {
			return content;
		}
	}

	public String getToUser() {
		return toUser;
	}

	public void setToUser(String toUser) {
		this.toUser = toUser;
	}

	public String getToParty() {
		return toParty;
	}

	public void setToParty(String toParty) {
		this.toParty = toParty;
	}

	public String getToTag() {
		return toTag;
	}

	public void setToTag(String toTag) {
		this.toTag = toTag;
	}

	public String getContent() {
		return content;
	}

	public void setContent(String content) {
		this.content = content;
	}

	public String getSafe() {
		return safe;
	}

	public void setSafe(String safe) {
		this.safe = safe;
	}

	public String getUrl() {
		return url;
	}

	public void setUrl(String url) {
		this.url = url;
	}

	public String getMsgType() {
		return msgType;
	}

	public Integer getAgentId() {
		return agentId;
	}

	public void setAgentId(Integer agentId) {
		this.agentId = agentId;
	}

}
